﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Configuration;

namespace Forex.IB.RealTimeBars.Components
{

    public class LogFile
    {
       

        private static string GetPath()
        {
            string path = Common.LogFile;
            return path;
        }

        public static void LogMessage(string message)
        {
            Object thisLock = new Object();
            lock (thisLock)
            {
                if (File.Exists(GetPath() + "RealTimeBars.log"))
                {
                    using (System.IO.StreamWriter sw = System.IO.File.AppendText(GetPath() + "RealTimeBars.log"))
                    {
                        sw.WriteLine(System.
                        String.Format("{0:G}: {1}.", System.DateTime.Now, message));
                    }
                }
                else
                {
                    using (System.IO.StreamWriter sw = System.IO.File.CreateText(GetPath() + "RealTimeBars.log"))
                    {
                        sw.WriteLine(System.
                        String.Format("{0:G}: {1}.", System.DateTime.Now, message));
                    }
                }
            }

        }
    }
}
